-- CALC_USER_MAX_MP

-----------------------------------------------
-- 玩家最大魔法值
-- @param  user  玩家
return function(user)
    local max_mp = user.dbase:query("max_mp", 0);

    -- 绝对值加成最大魔法值
    local prop = PropM.combine(user, "attrib2", "max_mp");
    max_mp = PropM.apply(prop, max_mp);

    -- 阵营加成最大魔法值
    local classId = user.dbase:query("active_pet", 0)
    local campId = CampM.getPetCamp(classId);
    prop = PropM.combine(user, "camp_max_mp", campId);
    max_mp = PropM.apply(prop, max_mp);

    -- 按系别攻击加成最大血量
    local departmentId = PetM.query(classId, "department_order")[1];
    prop = PropM.combine(user, "department_max_mp", departmentId);
    max_mp = PropM.apply(prop, max_mp);

    -- 贤者之语加成
    local stoneProp = ME.user.dbase:query("stone_prop", {});
    max_mp = max_mp + (stoneProp["max_mp"] or 0);

    -- 魔藤辅助
    local bine = user.bine;
    local bineAddon = user.dbase:query("bine_addon");
    if  type(bineAddon) == "table" and bine then
        max_mp = max_mp + (bineAddon["max_mp"] or 0);
    end

    -- 机械蜘蛛辅助
    local grids = SummonM.findSummonsByClassId(53);
    if #grids > 0 then
        local grid = grids[1];
        local summon = grid.summon;
        if summon and not summon:isDead() then
            prop = PropM.combine(summon, "attrib_to_user", 1);
            local summonMp = summon:queryAttrib("max_mp") or 0;
            max_mp = max_mp + FormulaM.invoke("CALC_BIG_DIVISION", summonMp, prop[3], 1000);
        end
    end

    -- 特定地图，魔法值+N
    local dungeonId = DungeonM.getDungeonId();
    local parentId = DungeonAreaM.getParentId(dungeonId);
    prop = PropM.combine(user, "dungeon_mp", parentId);
    max_mp = PropM.apply(prop, max_mp);

    -- 百分比加成最大魔法值
    prop = PropM.combine(user, "attrib", "max_mp");
    max_mp = PropM.apply(prop, max_mp);

    return max_mp;
end
